<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="jxl.*" %>
<%@ page import="jxl.write.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>删除信息</title>
</head>
<body>

<%
	String stuid = request.getParameter("stuid").trim();  	/*将 sid 的值传递过来，并赋值给stuid */
	File fileName = new File("D:/workplace/stuinfo.xls");
	Workbook book = Workbook.getWorkbook(fileName); 		/*创建只读的 Excel 工作薄的对象副本*/
	WritableWorkbook workbook  =  Workbook.createWorkbook(new File("D:/workplace/stuinfo.xls"), book);	 /* 创建真实写入的 Excel 工作薄对象*/
	WritableSheet sheet1 = (WritableSheet) workbook.getSheet(0);		 /*获得第一个工作表对象 */
	int rows = sheet1.getRows();          	 /*得到sheet1的总行数 */		
	
	//用循环语句，找到对应的行，并使用 remove。Row 方法删除对应行
	for(int i = rows;i>0;i--)
	{
		Cell cell1 = sheet1.getCell(0,i-1);
		String result = cell1.getContents();
		if(result.equals(stuid))
		{
			sheet1.removeRow(i-1);		
		}	
	}
	workbook.write();
	workbook.close();
	book.close();

	out.print("<script>alert('该学生信息已经成功删除，请返回！');</script>");
	out.print("<script>window.location='managerdeleteinfos.jsp';</script>");
%>

</body>
</html>